/**
 * 
 */
package daos;

import java.util.List;
import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Query;
import org.springframework.transaction.annotation.Transactional;

import model.Course;


public class CourseDAOImpl implements CourseDAO {
	
	private SessionFactory sessionFactory;
	
	@Transactional
	public Course findById(int courseId) {
		Session session = this.sessionFactory.getCurrentSession();
		return (Course)session.get(Course.class, courseId);
	}

	@Transactional
	public List<Course> getCourses() {
		Session session = this.sessionFactory.getCurrentSession();
		Query query = session.createQuery("from Course");
		return query.list();
	}

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
}